﻿﻿@model WebApp.Models.WaterManualReport
<!-- 弹出编辑窗体表单 -->
 <div id="watermanualreportdetailwindow" class="easyui-window" 
      title="编辑水表月度汇总记录" 
      data-options="modal:true,
                    closed:true,
                    minimizable:false,
                    collapsible:false,
                    maximized:false,
                    iconCls:'fal fa-window',
                    onRestore:function(){
                    },
                    onMaximize:function(){
                    }
                    " style="width:800px;height:450px;display:none">
  <!-- toolbar -->
  <div class="panel-content py-2 rounded-bottom border-faded border-left-0 border-right-0  text-muted bg-subtlelight-fade sticky-top">
  <div class="d-flex justify-content-end pr-4">
        <div class="btn-group btn-group-sm mr-1">
          <button name="saveitembutton"   class="btn btn-default">
            <i class="fal fa-save"></i> @Html.L("Save")
          </button>
        </div>
        <div class="btn-group btn-group-sm mr-1" id="deleteitem-btn-group">
          <button  name="deleteitembutton" class="btn btn-danger">
            <i class="fal fa-trash-alt"></i> @Html.L("Delete")
          </button>
        </div>
    </div>
  </div>
 <!-- panel container form  -->
 <div class="panel-container show">
   <div class="container">
    <div class="panel-content">
           <form id="watermanualreport_form" 
              class="easyui-form form-horizontal padding-10" 
              method="post" novalidate  >
  @Html.AntiForgeryToken()
   <!--Primary Key-->
  @Html.HiddenFor(model=>model.Id)
   <fieldset class="form-group">
   <div class="row h-100 align-items-center">

   <!--表号-->
        <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.meterId)</label>
		<div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">  
			<input id="@Html.IdFor(model => model.meterId)" 
				   name="@Html.NameFor(model => model.meterId)" 
				   value="@Html.ValueFor(model => model.meterId)"
				   tabindex="0" 
				   class="easyui-textbox" 
                   style="width:100%"
				   type="text" 
				   data-options="prompt:'@Html.DescriptionFor(model => model.meterId)',
								 required:false, 
                                 validType: 'length[0,20]'
                                 " />
       </div>
				   
   <!--表名-->
        <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.Name)</label>
		<div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">  
			<input id="@Html.IdFor(model => model.Name)" 
				   name="@Html.NameFor(model => model.Name)" 
				   value="@Html.ValueFor(model => model.Name)"
				   tabindex="1" 
				   class="easyui-textbox" 
                   style="width:100%"
				   type="text" 
				   data-options="prompt:'@Html.DescriptionFor(model => model.Name)',
								 required:false, 
                                 validType: 'length[0,50]'
                                 " />
       </div>
				   

   <!--表序号-->
        <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.LineNo)</label>
		<div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">  
			<input id="@Html.IdFor(model => model.LineNo)" 
				   name="@Html.NameFor(model => model.LineNo)" 
				   value="@Html.ValueFor(model => model.LineNo)"
				   tabindex="2" 
				   class="easyui-textbox" 
                   style="width:100%"
				   type="text" 
				   data-options="prompt:'@Html.DescriptionFor(model => model.LineNo)',
								 required:false, 
                                 validType: 'length[0,50]'
                                 " />
       </div>
				   
   <!--出线名称-->
        <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.Name1)</label>
		<div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">  
			<input id="@Html.IdFor(model => model.Name1)" 
				   name="@Html.NameFor(model => model.Name1)" 
				   value="@Html.ValueFor(model => model.Name1)"
				   tabindex="3" 
				   class="easyui-textbox" 
                   style="width:100%"
				   type="text" 
				   data-options="prompt:'@Html.DescriptionFor(model => model.Name1)',
								 required:false, 
                                 validType: 'length[0,50]'
                                 " />
       </div>
				   

   <!--本期读数-->
       <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"><span class="text-danger">*</span> @Html.DisplayNameFor(model => model.Water)</label>
	   <div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">  
             <input id="@Html.IdFor(model => model.Water)"
				   name="@Html.NameFor(model => model.Water)" 
				   value="@Html.ValueFor(model => model.Water)"
				   tabindex="4" 
				   class="easyui-numberbox" 
                   style="width:100%"
				   type="text" 
				   data-options="prompt:'@Html.DescriptionFor(model => model.Water)',
								 required:true,formatter:numberformatter,
                                 parser:parsernumber,precision:2,
                                 
                                 "  />

        </div>
				   
   <!--抄表日期-->
        <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"><span class="text-danger">*</span> @Html.DisplayNameFor(model => model.RecordDate)</label>
		<div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">  
                <input id="@Html.IdFor(model => model.RecordDate)" 
			       name="@Html.NameFor(model => model.RecordDate)"
                   value="@Html.ValueFor(model => model.RecordDate)"
           		   tabindex="5"  required
				   class="easyui-datebox" 
                   style="width:100%"
				   type="text" 
				   data-options="prompt:'@Html.DescriptionFor(model => model.RecordDate)',
								 required:true,
								 formatter:dateformatter" />
     </div>
				   

   <!--上期读数-->
       <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.LastWater)</label>
	   <div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">  
             <input id="@Html.IdFor(model => model.LastWater)"
				   name="@Html.NameFor(model => model.LastWater)" 
				   value="@Html.ValueFor(model => model.LastWater)"
				   tabindex="6" 
				   class="easyui-numberbox" 
                   style="width:100%"
				   type="text" 
				   data-options="prompt:'@Html.DescriptionFor(model => model.LastWater)',
								 required:false,formatter:numberformatter,
                                 parser:parsernumber,precision:2,
                                 
                                 "  />

        </div>
				   
   <!--上期抄表日期-->
        <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.LastRecordDate)</label>
		<div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">  
                <input id="@Html.IdFor(model => model.LastRecordDate)" 
			       name="@Html.NameFor(model => model.LastRecordDate)"
                   value="@Html.ValueFor(model => model.LastRecordDate)"
           		   tabindex="7"  
				   class="easyui-datebox" 
                   style="width:100%"
				   type="text" 
				   data-options="prompt:'@Html.DescriptionFor(model => model.LastRecordDate)',
								 required:false,
								 formatter:dateformatter" />
     </div>
				   

   <!--本期用水量-->
       <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.CalWater)</label>
	   <div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">  
             <input id="@Html.IdFor(model => model.CalWater)"
				   name="@Html.NameFor(model => model.CalWater)" 
				   value="@Html.ValueFor(model => model.CalWater)"
				   tabindex="8" 
				   class="easyui-numberbox" 
                   style="width:100%"
				   type="text" 
				   data-options="prompt:'@Html.DescriptionFor(model => model.CalWater)',
								 required:false,formatter:numberformatter,
                                 parser:parsernumber,precision:2,
                                 
                                 "  />

        </div>
				   
   <!--备注-->
        <label class="col-md-2 col-sm-3 col-xs-3 col-3 pt-1 pl-0 pr-0 form-label text-right"> @Html.DisplayNameFor(model => model.Remark)</label>
		<div class="col-md-4 col-sm-9 col-xs-9 col-9 mb-1 pl-1">  
			<input id="@Html.IdFor(model => model.Remark)" 
				   name="@Html.NameFor(model => model.Remark)" 
				   value="@Html.ValueFor(model => model.Remark)"
				   tabindex="9" 
				   class="easyui-textbox" 
                   style="width:100%"
				   type="text" 
				   data-options="prompt:'@Html.DescriptionFor(model => model.Remark)',
								 required:false, 
                                 validType: 'length[0,250]'
                                 " />
       </div>
				   
	    </div> 
      </fieldset>
   </form>
    </div>
    </div>
    </div>
</div>

<!-- 弹出窗体form表单 -->
<!-- 弹出编辑对话框 -->

<!--begin popup detailview javascript block -->
<script type="text/javascript">
 //当初始的 HTML 文档被完全加载和解析完成之后
 document.addEventListener('DOMContentLoaded', function () {
     //绑定按钮事件
    $('button[name="saveitembutton"]').on('click', savewatermanualreportitem);
   $('button[name="deleteitembutton"]').on('click', deletewatermanualreportitem);
   initwatermanualreportdetailview();
  });
    //判断新增编辑状态
    var MODELSTATE = 'Added';
    var watermanualreportid = null;
    function openwatermanualreportdetailwindow(data,state) {
         MODELSTATE = state;
         //判断是否显示功能按钮
        if (MODELSTATE === 'Added') {
          $('#deleteitem-btn-group').hide();
        } else {
          $('#deleteitem-btn-group').show();
        }
     
         watermanualreportid = (data.Id || 0);
         $('#watermanualreportdetailwindow').window('open');
         $('#watermanualreport_form').form('reset');
         $('#watermanualreport_form').form('load', data);
             }
  //删除当前记录
  function deletewatermanualreportitem() {
    $.messager.confirm('确认', '你确定要删除该记录?', result => {
      if (result) {
        const url = `/WaterManualReports/Delete/${watermanualreportid}`;
        $.get(url).done(res => {
          if (res.success) {
            toastr.success("删除成功");
            $('#watermanualreportdetailwindow').window('close');
            reloadData();
          } else {
            $.messager.alert('错误', res.err, 'error');
          }
        });
      }
    });
  }
    //async 保存数据
    async function savewatermanualreportitem() { 
      const $watermanualreportform = $('#watermanualreport_form');
      if ($watermanualreportform.form('enableValidation').form('validate')) {
            let watermanualreport = $watermanualreportform.serializeJSON();
            let url = '/WaterManualReports/Edit';
            //判断是新增或是修改方法
            if (MODELSTATE === 'Added') {
                url = '/WaterManualReports/Create';
            }
            var token = $('input[name="__RequestVerificationToken"]', $watermanualreportform).val();
            $.ajax({
                    type: "POST",
                    url: url,
                    data: {
                        __RequestVerificationToken: token,
                        watermanualreport:watermanualreport
                    },
                    dataType: 'json',
                    contentType: 'application/x-www-form-urlencoded; charset=utf-8'
                })
                .done(response => {
                    if (response.success) {
                        hook = false;
                        $watermanualreportform.form('disableValidation');
                        $watermanualreportform.form('submitChanged');
                        $('#watermanualreportdetailwindow').window("close");
                        toastr.success("保存成功"); 
                        reloadData();
                    } else {
                        $.messager.alert("错误",   response.err, "error");
                    }
                    })
                .fail((jqXHR, textStatus, errorThrown) => {
                       $.messager.alert('异常', `${jqXHR.status}: ${jqXHR.statusText} `, 'error');
                    });
        }
    }
     //判断是否有没有保存的记录
     function watermanualreporthasmodified() {
            return hook;

     }


function initwatermanualreportdetailview() {
//回车光标移动到下个输入控件
    //如果是枚举类型需要把numberbox改成combobox
    //本期读数
	$('#Water').numberbox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //如果是枚举类型需要把numberbox改成combobox
    //上期读数
	$('#LastWater').numberbox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //如果是枚举类型需要把numberbox改成combobox
    //本期用水量
	$('#CalWater').numberbox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //日期类型 抄表日期
	$('#RecordDate').datebox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
    //日期类型 上期抄表日期
	$('#LastRecordDate').datebox('textbox').bind('keydown', function (e) {
      if (e.keyCode == 13) {
        $(e.target).emulateTab();
      }
    });
}
</script>

